/***************************************************************************
 *            directory.c
 *
 *  Thu Oct  9 18:14:03 2008
 *  Copyright  2008  ra046802
 *  <ra046802@zero.lab.ic.unicamp.br>
 ****************************************************************************/

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */
#include "directory.h"
 
 index_string * directory_to_index(char * dirname){
	DIR *dp;
	struct dirent *ep;
	char * name;
	index_string * index=index_string_create();

	dp = opendir (dirname);
	if (dp != NULL)
	    {
	    while (ep = readdir (dp)){
	        //puts (ep->d_name);
	        if(ep->d_name[0]!='.'){
	        name=malloc((strlen(ep->d_name)+1)*sizeof(char));
	    strcpy(name,ep->d_name);
index_string_add(index,name);	    
printf("%s\n",name);
	        }
	}
	    (void) closedir (dp);
	    }
	else
	    perror ("Couldn't open the directory");
return index;
}
